package String类;

public class CharSequenceDemo {
  public static void main(String[] args) {
	 testString();
	 testStringBuffer();
	 testStringBuilder();
	 
  }
  public static void testString(){
	  long begin = System.currentTimeMillis();
	  String str="";
	  for (int i = 0; i < 30000; i++) {
		 str+=i;
	}
	  long end=System.currentTimeMillis();
	  System.out.println("String消耗时间："+(end-begin));
  }
  public static void testStringBuffer(){
	  long begin = System.currentTimeMillis();
	  StringBuffer sb=new StringBuffer();
	  for (int i = 0; i < 30000; i++) {
		 sb.append(i);
	}
	  long end=System.currentTimeMillis();
	  System.out.println("StringBuffer消耗时间："+(end-begin));
  }
  public static void testStringBuilder(){
	  long begin = System.currentTimeMillis();
	  StringBuilder sb=new StringBuilder();	
	  for (int i = 0; i < 30000; i++) {
		 sb.append(i);
	}
	  long end=System.currentTimeMillis();
	  System.out.println("StringBuilder消耗时间："+(end-begin));
  }
}
